#include<iostream>
#include<vector>
#include<string>
using namespace std;

class Book
{
    public:
    Book(int bookid , string bookname)
    {
        bookId = bookid;
        bookName = bookname;

    }
    int bookId;
    string bookName;

};
class Library
{
    public:
    
    vector<Book> v;
    void push(Book b_i)
    {
        v.push_back(b_i);
    }
    void addBook(int bookid,string bookname)
    {
        cout << "图书 " << bookname <<" 已成功添加到图书馆！" << endl;

    }
    void displayBooks()
    {
        cout << "当前图书馆图书列表：" << endl;
        for(int i = 0;i < v.size();i++)
        {
            cout << "编号：" << v.at(i).bookId << ", 书名： " << v.at(i).bookName << endl;
            
        }
        
        
    }
    void displayBooks(int bbk)
    {
        cout << "当前图书馆图书列表：" << endl;
        for(int i = 0;i < v.size();i++)
        {
            if(i == bbk)
            {
                cout << "编号：" << v.at(i).bookId << ", 书名： " << v.at(i).bookName << "该书以被借阅" <<endl;
            }
            else
            {
                
                
                cout << "编号：" << v.at(i).bookId << ", 书名： " << v.at(i).bookName << endl;
            }
        }
        
        
    }
    void findBookById(int bookid)
    {
        cout << "找到图书：编号" << v.at(bookid - 1).bookId << ", 书名： " << v.at(bookid - 1).bookName << endl;

    }
    int removeBookByI(int bookid,int bbk1)
    {
        cout << "图书已成功删除。" << endl;
        
        vector<Book>::iterator it = v.begin() + bookid - 1;
        //auto it = v.begin() + bookid;
        v.erase(it);
        if(bbk1 >  bookid - 1)
        {
            return bbk1 - 1;
        }
        else if(bbk1 < bookid - 1)
        {
            return bbk1;
        }
        else
        {
            return -1;
        }
        
    }
    int borrowBook(int bookid)
    {
        cout << "图书 " << v.at(bookid - 1).bookName << " 已成功借阅！" << endl;
        return bookid - 1;
    }

};


int main()
{
    Library library;
    string bookname;
    int bookid;
    int booknum;
    cout << "你要存入几本书？" << endl;
    cin >> booknum;
    for (int i = 1;i <= booknum; i++)
    {
        cout << "第" << i << "本书的名字为：";
        cin >> bookname;
        library.addBook(i, bookname);
        Book b_i(i ,bookname);
        library.push(b_i);
    }
    library.displayBooks();
    

    library.findBookById(2);

    int bbk1 = library.borrowBook(2);

    library.displayBooks(bbk1);
    

    int bbk2 = library.removeBookByI(1,bbk1);

    library.displayBooks(bbk2);
    
    
    return 0;

}
